import Vue from 'vue'
// 将时间戳格式化
Vue.filter('formatTime', (time, number, isComment) => {
  let curDate = new Date()
  let curTimeStamp = new Date().getTime()
  let date = new Date(time) // 如果time是13位, 则不需要乘1000
  let Y = date.getFullYear()
  let M = (date.getMonth() + 1).toString().padStart(2, '0')
  let D = date.getDate().toString().padStart(2, '0')
  let h = date.getHours().toString().padStart(2, '0')
  let m = date.getMinutes().toString().padStart(2, '0')
  let s = date.getSeconds().toString().padStart(2, '0')
  if (isComment) {
    // 大于1小时小于1天的评论，显示 时:分
    let timecha = curTimeStamp - time
    if (timecha < 24 * 3600 * 1000
      && timecha > 3600 * 1000) {
      return `${h}:${m}`
    } else if (timecha < 3600 * 1000 && timecha > 60 * 1000) {
      // 大于1分钟，小于1小时内评论的
      if (curDate.getHours() == parseInt(h, 10)) {
        let minutes = curDate.getMinutes() - parseInt(m, 10)
        return `${minutes}分钟前`
      } else {
        let minutes1 = curDate.getMinutes() + (60 - parseInt(m, 10))
        return `${minutes1}分钟前`
      }
    } else if (timecha < 60 * 1000) { // 小于1分钟内评论的
      if (curDate.getMinutes() == parseInt(m, 10)) {
        let seconds = curDate.getSeconds() - parseInt(s, 10)
        return `${seconds}秒前`
      } else {
        let seconds1 = curDate.getSeconds() + (60 - parseInt(s, 10))
        return `${seconds1}秒前`
      }
    } else {
      return `${Y}年${M}月${D}日`
    }
  }
  Y = Y + '-'
  M = M + '-'
  h = h + ':'
  m = m + ':'
  switch (number) {
    case 3:
      return h+m+s;
    case 6:
      return Y+M+D+h+m+s
    default:
      return Y+M+D
  }
  
})
/*
* 处理播放量
* */
Vue.filter('handlerPlayCount', playCount => {
  if (parseInt(playCount / 100000000) >= 1) {
      return parseInt(playCount / 100000000) + '亿'
  } else if (parseInt(playCount / 10000) >= 1) {
    return parseInt(playCount / 10000) + '万'
  } else {
    return parseInt(playCount)
  }
})

Vue.filter('formatPlayListDesc', desc => {
  let descList = desc.split('\n')
  let newList = descList.map(item => {
    return item + ''
  })
  return newList.join()
})

